package com.lsu.app.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lsu.app.bean.Collect;
import com.lsu.app.service.CollectService;
import com.lsu.app.mapper.CollectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;
import java.util.Set;

/**
 *
 * @description 针对表【collect(收藏/关注)】的数据库操作Service实现
 * @Date 2023-10-18 20:22:23
 * @author hjj
 */
@Service
public class CollectServiceImpl extends ServiceImpl<CollectMapper, Collect> implements CollectService{
    private final CollectMapper mapper;
    @Autowired
    private HttpServletRequest request;

    public CollectServiceImpl(CollectMapper mapper) {
        this.mapper = mapper;
    }

    @Override
    public Integer collectCount(Integer linkId,Integer type) {
        return mapper.collectCount((Integer) request.getSession().getAttribute("id"), linkId,type)==0?0:1;
    }

    @Override
    public Integer CountByTeacherId(Integer teacherId) {
        return mapper.CountByTeacherId(teacherId);
    }

    @Override
    public Integer isCollect(Integer linkId, Integer userId) {
        return mapper.collectCount(userId,linkId,1)!=0?1:0;
    }

    @Override
    public Set<Integer> CourseKindIdsByUserId(Integer userId) {
        return mapper.CourseKindIdsByUserId(userId);
    }
}




